import instance from "@/main";

export const getPricingPrice = {
  computed: {
    // 计算点价价格
    getPricingPrice() {
      return (contract, premium) => {
        let lastPrice = 0;
        if (
          contract &&
          instance.$store.state.socketFuture.futureData[contract.toLowerCase()]
        ) {
          lastPrice = Number(
            instance.$store.state.socketFuture.futureData[
              contract.toLowerCase()
            ].lastPrice || 0
          );
        }
        let price = parseInt(lastPrice + Number(premium));
        return price;
      };
    },
    // 行情价格变动
    pricingPriceChange() {
      return contract => {
        let range = 0;
        if (
          contract &&
          instance.$store.state.socketFuture.futureData[contract.toLowerCase()]
        ) {
          range = Number(
            instance.$store.state.socketFuture.futureData[
              contract.toLowerCase()
            ].change || 0
          );
        }
        // 浮动大于0是涨，小于0是跌
        let res = range > 0 ? "danger" : range < 0 ? "success" : "";
        return res;
      };
    }
  }
};
